package com.lzy.cloud.goods.controller;

import com.lzy.cloud.goods.dtos.CarDraftDto;
import com.lzy.cloud.goods.request.CarChassisRequest;
import com.lzy.cloud.goods.service.CarDraftService;
import com.lzy.framework.core.ensure.Ensure;
import com.lzy.framework.core.output.Result;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by WIN7 on 2018/6/13.
 */
@RestController
@RequestMapping("/goods/car/draft")
public class CarDraftController {

    @Autowired
    CarDraftService carDraftService;

    /**
     * 删除车型草稿
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/del/{id}",method = RequestMethod.GET)
    public Result del(@PathVariable("id") Long id){
        Boolean ok = carDraftService.del(id);
        Ensure.that(ok).isTrue("00070001");
        return new Result(ok);
    }

    /**
     * 获取车型草稿列表
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public Result selectList(CarChassisRequest request){
        Ensure.that(request).isNotNull("00010001");
        List<CarDraftDto> carDraftDtoList = carDraftService.selectList(DozerUtils.map(request, CarDraftDto.class));
        return new Result(carDraftDtoList);
    }
}
